<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AngularJS&middot;Hello AngularJS</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <style>
        .demo{
            margin-bottom:10px;
            border-bottom:1px solid #1b926c;
        }
    </style>
</head>
<body>

 <div class="container">
     <div class="row">
         <nav class="navbar navbar-default navbar-static-top">
             <div class="container-fluid">
                 <div class="navbar-header">
                     <a class="navbar-brand" href="../index.html">首页</a>
                 </div>
                 <ul class="nav navbar-nav">
                    <li class="active"><a href="javascript:void(0)">Link</a></li>
                    <li><a href="javascript:void(0)">Link2</a></li>
                 </ul>
             </div>
         </nav>
     </div>
     <div ng-app="myApp">
     <div class="row demo">
         <div ng-controller="CookieController">
             <h4>{{title}}</h4>
             <ul>
                 <li>Name:{{person.name}}</li>
                 <li>Age:{{person.age}}</li>
             </ul>
             <button class="btn btn-success" ng-click="getCookieValue()">显示其他cookie</button>
             <br/>
         </div>
     </div>
     </div>
 </div>
</body>
</html>
<script src="../static/js/angular-1.3.15/angular.js" type="text/javascript"></script>
<script src="../static/js/angular-1.3.15/angular-cookies.js"></script>
<script>
    var myApp=angular.module('myApp', ['ngCookies']);
    myApp.controller("CookieController",function($cookieStore, $scope){
        $scope.title = "Angular操作cookie练习";

        $cookieStore.put("name","我是小小强");
        $cookieStore.put("age",20);
        if($cookieStore.get("name") ){
            alert($cookieStore.get("name"));
            $cookieStore.remove("name");
        }

        $cookieStore.put("persion", {
            name: "小强",
            age: 18
        });

        $scope.person = $cookieStore.get("persion");

        $scope.getCookieValue=function(){
            alert($cookieStore.get("age"));
        };
    });
</script>
